package cn.edu.neusoft.food229.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import cn.edu.neusoft.food229.R;
import cn.edu.neusoft.food229.activity.AllCommentActivity;
import cn.edu.neusoft.food229.activity.AllorderActivity;
import cn.edu.neusoft.food229.activity.FoodActivity;
import cn.edu.neusoft.food229.activity.SettingActivity;

import static android.content.Context.MODE_PRIVATE;

public class Fragment4 extends FragmentBase_229{
    private TextView tv;
    private Context context;
    private View view=null;
    private TextView tv_name;
    private ImageButton imageButton ,go,goes;
    private SharedPreferences sp;
    private String User_name;
    public Fragment4() {

    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
        sp=context.getSharedPreferences("login",MODE_PRIVATE);

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment4,container,false);

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        System.out.println("-----f4-----");
        initEvents(view);


    }



    private void initEvents(View view) {
        User_name=sp.getString("username","");
        tv_name=view.findViewById(R.id.user_nm);
        tv_name.setText(User_name);
        go=view.findViewById(R.id.last1);
        goes=view.findViewById(R.id.last2);
        go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AllorderActivity.class);
                context.startActivity(intent);
            }
        });
        goes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AllCommentActivity.class);
                context.startActivity(intent);
            }
        });
        imageButton=view.findViewById(R.id.last);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("-----设置页-----");
                Toast.makeText(context, "设置", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, SettingActivity.class);
                context.startActivity(intent);
            }
        });


    }
}
